<template>
    <div class="cartcontrol">
        <transition>
            <div class="cart-decrease" v-show="food.count> 0"  @click.stop.prevent="decreaseC">-</div>
        </transition>
        <div class="cart-count" v-show="food.count> 0">{{food.count}}</div>
        <div class="cart-plus" @click.stop.prevent="addClick">+</div>
    </div>
</template>

<script>
import Vue from 'vue'
export default {
    props: ['food'],
    methods: {
        addClick (e) {
            if (!e._constructed) {
                return
            }
            // console.log(this.food.count)
            if (!this.food.count) {
                Vue.set(this.food, 'count', 1)
            } else {
                this.food.count++
            }
        },
        decreaseC (e) {
            if (!e._constructed) {
                return
            }
            if (this.food.count) {
                this.food.count--
            }
        }
    }
}
</script>

<style lang="scss" scoped>
    .v-enter,
    .v-leave-to {
        opacity: 0;
        transform: translateX(36px);
    }
    .v-enter-active,
    .v-leave-active {
        transition: all 0.4s linear;
    }

    .cartcontrol {
        display: flex;
        justify-content: center;
        align-items: center;
        box-sizing: border-box;
        .cart-decrease {
            font-size: 24px;
            color: rgb(0,160,220);
            line-height: 17px;
            text-align: center;
            background-color: #fff;
            width: 24px;
            height: 24px;
            border-radius: 50%;
            border: 2px solid rgb(0,160,220);
            box-sizing: border-box;
        }
        .cart-count {
            padding: 0 12px;
            vertical-align: top;
            width: 12px;
            line-height: 24px;
            font-size: 12px;
            color: rgb(147, 153, 159)
        }
        .cart-plus {
            font-size: 22px;
            color: #fff;
            line-height: 22px;
            text-align: center;
            background-color: rgb(0,160,220);
            width: 24px;
            height: 24px;
            border-radius: 50%
        }
    }
</style>